package cn.io.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @author summit
 * @since 2022/5/12 15:35
 */
public class NioClient {

	public static void main(String[] args) throws IOException {
		SocketChannel channel = SocketChannel.open();
		channel.configureBlocking(false);
		InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 9999);

		if (!channel.connect(inetSocketAddress)) {
			while (!channel.finishConnect()) {
				System.out.println("working=================");
			}
		}

		String msg = "hello nio server";
		ByteBuffer bb = ByteBuffer.wrap(msg.getBytes());
		channel.write(bb);

		System.in.read();
	}
}
